function WeatherAlarm() {
	var data = {};
	initData();
	function initData() {
		$.getJSON("/rest/getWeatherAlarmDialogData/" + weatherWarningId,
				function(result) {
					// {warning:{},lines:[],stations:[],info:{weatherNum:0,faultNum:}}
					data = result;
					drawHtml();
				});
	}
	function drawHtml() {
		drawDisc();
		drawBtns($('#lines'), data.lines);
		drawBtns($('#stations'), data.stations);
	}
	function drawBtns(div, equipments) {
		div.html('');
		if(equipments && equipments.length>0){
			for ( var i in equipments) {
				var btnClass = "";
				var e = equipments[i];
				if (e.faultNum) {
					btnClass = " faultBtn";
				}
				var title = e.equipmentName;
				var name = title.length > 5 ? title.substring(0, 5) + "..." : title;
				var equipment = '<button class="btn equipmentBtn' + btnClass
				+ '" onclick="clickButtonSearch(this);" title="' + title
				+ '">' + name + '</button>';
				div.append(equipment);
			}
		}else{
			div.html('无');
		}
	}
	function drawDisc() {
		var typeIcon = $("#typeIcon");
		var atype = data.warning.atype;
		var s = "<br/>共发生相关故障：<span class='box-num'>" + data.faultNum+"</span>次。";
		
		var areaDisc = $("#areaDisc");	
		$.getJSON("/rest/getWeatherAlertDescriptionByWarningId/"+data.warning.id,function(result){
			areaDisc.html('');
			if(result.length>0){
				var con = "";
				var c2 = "本地区";
				for(var i in result){
					var r = result[i];
					if(r.years[0] && r.years[1]){
						con += r.name+"数据区间："+r.years[0]+"-"+r.years[1]+"。</br>";
					}else{
						con += r.name+"数据区间：获取失败。</br>";
					}
					con += r.name+"："+r.details+"</br>";
					c2 += "历史出现"+r.name+"：<span class='box-num'>"+r.weatherNum+"</span>次，";
				}
				c2 = c2.substring(0, c2.length-1)+"。";
				$("#iconDiv").append(getQuestionIcon(con));
				areaDisc.append(c2);
				areaDisc.append(s);
			}else{
				var con = "此天气类型暂时无法获取历史数据。";
				$("#iconDiv").append(getQuestionIcon(con));
				areaDisc.append("本地区历史" + atype + "出现总次数：未知。");
				areaDisc.append(s);
				areaDisc.css("padding","10px");
			}
			if(data.warning.icon){
				typeIcon.addClass(data.warning.icon);
			}else{
				typeIcon.addClass("fa fa-cloud");
			}
			
		});
	}
	function getQuestionIcon(text){
		return "<span class='fa fa-question-circle' onmouseover=\"showHint('"+text+"')\" " +
		"onmouseout='hideHint()' style='margin:5px;font-size: 16px;float: right;cursor: pointer;'></span>";
		
	}
	function getIcon(atype) {
		var icon = "";
		if (atype.indexOf("雨") != -1) {// fa-tint fa-umbrella
			icon = "glyphicon glyphicon-tint";
		} else if (atype.indexOf("雷") != -1) {
			icon = "glyphicon glyphicon-flash";
		} else if (atype.indexOf("寒") != -1 || atype.indexOf("冰") != -1
				|| atype.indexOf("冻") != -1 || atype.indexOf("雪") != -1) {
			icon = "fa fa-exclamation";
		} else if (atype.indexOf("风") != -1) {// fa-flag-o
			icon = "fa fa-flag-o";
		} else if (atype.indexOf("火") != -1) {// fa-fire glyphicon
			// glyphicon-fire
			icon = "glyphicon glyphicon-fire";
		} else {
			icon = "fa fa-thermometer-full";
		}
		return icon;
	}
}
function showHint(con) {//显示提示框
	var mousePos = getMousePosition();//鼠标位置
	$("#hint").html(con);//赋值
	var hintHei = $("#hint").height();
	hintDiv.css({
		"height" : hintHei + 5,
		"display" : "block",
		"left" : mousePos.x - 310,
		"top" : mousePos.y - 10
	}).html(con);
}
function hideHint(){//隐藏提示框
	$("#hint").hide();
}
// 提示框
var hintDiv = $("<div></div>").attr("id", "hint").css({
	"width" : 300,
	"background" : "white",
	"border" : "1px solid",
	"padding" : "0px 3px 0px 3px",
	"position" : "absolute"
}).appendTo("body").hide();
// 获取鼠标位置
function getMousePosition() {
	var ev = window.event;
	if (ev.pageX || ev.pageY) {
		return {
			x : ev.pageX,
			y : ev.pageY
		};
	}
	return {
		x : ev.clientX + doucument.body.scrollLeft - document.body.clientLeft,
		y : ev.clentY + document.body.scrollTop - document.body.clientTop
	};
}
function ProtectionPanel() {
	var data = undefined;
	var table = undefined;
	this.search = function(value) {
		table.search(value).draw();
	};
	getProtectionEqipments();
	function getProtectionEqipments() {
		$.getJSON('/rest/getProtectionByWeatherWarningId/' + weatherWarningId,
				function(result) {
					data = result;
					drawProtectTable("protects");
				});
	}
	function drawProtectTable(tbId) {
		var opt = MyTable.getDefaultOptions();
		opt.paging = true;
		opt.ordering = true;
		opt.searching = true;
		opt.columnDefs = [ ];
		opt.autoWidth = false;
		opt.pageLength = 7;
		opt.scrollCollapse = false;
		var columns = [ '序号', '类型','时间', '内容', '详情'];
		var tab = new MyTable(tbId, columns, opt);
		tab.setDataSet(getDataset());
		tab.show(tbId);
		table = tab.getTable();
		/*// 鼠标滑过事件
		$('#' + tbId + ' tbody').on(
				'mouseover',
				'tr',
				function() {
					var selectedData = null;
					var message1 = "";
					if ($(this).hasClass('selected')) {
						$(this).removeClass('selected');
					} else {
						table.$('tr.selected').removeClass('selected');
						$(this).addClass('selected');
					}
					selectedData = table.row('.selected').data();
					if (selectedData != null
							&& typeof (selectedData) != "undefined") {
						var privateId = selectedData[5];
						$.getJSON("/rest/protectAlarm/getChannelStatusByPrivateId/"
										+ privateId, function(result) {
									message1 = drawTitleSpan(result);
									$.getJSON("/rest/protectAlarm/getDevidesStatusByPrivateId/"
											+ privateId,
											function(result) {
												drawDetialSpan(result,
														message1);
											});
										});
					}
				});
		$('#' + tbId + ' tbody').on('mouseout', 'tr', function() {
			var table = $('#' + tbId).DataTable();
			table.$('tr.selected').removeClass('selected');
			var Meg = document.getElementById("Meg");
			Meg.style.display = "none";
			var disc = document.getElementById('Disc');
			disc.style.display = "block";
		});*/
	}
	function getDataset() {
		var dataset = [];
		for ( var i in data) {
			var d = data[i];
			var opt = '<button onclick="gotoDetail(this)" data-msgType="'+d.msgType+'" data-id="'+d.source+'" class="btn btn-primary fa fa-search"/>';
			dataset.push([ Number(i)+1, getStr(d['type']),
					DateUtil.locale(d['createTime']), getStr(d['content']),
					opt]);
		}
		return dataset;
	}
	function getStr(value) {
		return value?value:'';
	}
}

function drawTitleSpan(result) {
	var data = result["0"];
	var message = '';
	if (data != null) {
		var time = getTimeStr(data.triggerTime.time);
		var c = data.alarmChannel;
		message = '<span><strong><i class="icon fa fa-warning"></i>通讯异常</strong></span><br/><strong>'
				+ time
				+ "</strong><span style=''><br/>告警对象："
				+ data.alarmObject
				+ '<br/> 内容：'
				+ c.substring(c.indexOf("通道") == -1 ? 0 : c.indexOf("通道"),
						c.length)
				+ "</span>发生<span style='margin:5px'>"
				+ data.name + "</span>";
	}
	return message;
}

function drawDetialSpan(result, message1) {
	var data = result["0"];
	var message2 = "";
	if (data != null) {
		message2 = '<span><strong><i class="icon fa fa-warning"></i>运行异常</strong></span><br/><strong>'
				+ getTimeStr(data.alarm_time)
				+ '</strong></span><br/>内容：<span style="margin:5px;">'
				+ data.alarm_name + "</span>";
	}
	var megDiv = document.getElementById("messaageDiv");
	var megDiv2 = document.getElementById("messaageDiv2");
	if (message1 != "") {
		megDiv.innerHTML = message1;
		megDiv2.innerHTML = message2;
	} else {
		megDiv.innerHTML = message2;
	}
	var disc = document.getElementById('Disc');
	disc.style.display = "none";
	var Meg = document.getElementById("Meg");
	Meg.style.display = "block";
	var className = document.getElementById("typeIcon").className;
	var typeIcon2 = document.getElementById("typeIcon2");
	typeIcon2.setAttribute('class', className);
}
function getTimeStr(millis) {
	var time = new Date(millis);
	return time.getFullYear() + '年' + (time.getMonth() + 1) + '月'
			+ time.getDate() + '日 ' + time.getHours() + '时' + time.getMinutes()
			+ '分' + time.getSeconds() + '秒';
}
function gotoDetail(ele) {
	var fra = document.createElement("iframe");
	fra.style = "background:transparent;border:0;";
	fra.width = "100%";
	fra.id = "iframe";
	fra.height = "650px";
	var id = $(ele).attr('data-id');
	var msgType = $(ele).attr('data-msgType');
	var url = getUrl(msgType,id);
	fra.src = url;
	document.body.appendChild(fra);
	$('#baseInfo').css('display', 'none');
};
function backFromChild() {
	document.body.removeChild(document.getElementById("iframe"));
	$('#baseInfo').css('display', 'block');
	table.getTable().draw();
}
function getUrl(msgType,sourceId){
	var url = '';
	switch (msgType) {
	case "hlyc":
		url = "/ui/map/dialog/riskAlarmDialog/protectDeviceException.xhtml?oId="
						+ sourceId+"&showBackBtn=true";
		break;
	case "tdyc_single":
	case "tdyc_double":
		url = "/ui/map/dialog/riskAlarmDialog/protectChannelException.xhtml?oId="
						+ sourceId+"&showBackBtn=true";
		break;
	}
	return url;
}